package com.woniuxy.microgoodsserver.auctionmag.mapper;

import com.woniuxy.microgoodsserver.bean.*;
import org.apache.ibatis.annotations.*;
import org.apache.ibatis.mapping.FetchType;

import java.util.Date;
import java.util.List;

@Mapper
public interface ImageMapper {
    //图片通过id查询
    @Results({
            @Result(id=true,property = "id",column = "id",javaType = int.class),
            @Result(property = "image",column = "image",javaType = String.class),
            @Result(property = "imageName",column = "image_name",javaType = String.class),
            @Result(property = "imageMs",column = "image_ms",javaType = String.class),
            @Result(property = "imageNumble",column = "image_numble",javaType = String.class),
            @Result(property = "imagePx",column = "image_px",javaType = int.class),
            @Result(column = "fk_xc_id",property = "imageXcBean",javaType = ImageXcBean.class,
                    one = @One(select = "com.woniuxy.microgoodsserver.auctionmag.mapper.ImageXcMapper.xcFindAllById",fetchType = FetchType.LAZY))
    })
    @Select("select id,image,image_name,image_ms,image_numble,image_px,fk_xc_id from t_image_info where id = #{id} and del_status=0")
    ImageBean imageFindAllById(@Param("id")int id);

    //图片分页查询
    List<ImageBean> imageFindAll(@Param("p") PageRequest request, @Param("i")ImageBean imageBean);


    //图片增加
    @Options(useGeneratedKeys = true,keyProperty = "i.id")
    @Insert("insert into t_image_info " +
            "(image,image_name,image_ms,image_numble,image_px,fk_xc_id,del_status)" +
            " values(#{i.image},#{i.imageName},#{i.imageMs},#{i.imageNumble}," +
            "#{i.imagePx},#{i.imageXcBean.id},'0')")
    int SaveImage(@Param("i") ImageBean ImageBean);


    //图片修改
    @Update("<script>" +
            "update t_image_info" +
            "<set>" +
            "<if test='i.imageName != null'>" +
            " image_name = #{i.imageName}," +
            "</if>" +
            "<if test='i.imageMs != null'>" +
            " image_ms = #{i.imageMs}," +
            "</if>" +
            "<if test='i.image != null'>" +
            " image = #{i.image}," +
            "</if>" +
            "<if test='i.imagePx != null'>" +
            " image_px = #{i.imagePx}," +
            "</if>" +
            "</set>" +
            "where id = #{i.id}" +
            "</script>")
    int updateImage(@Param("i") ImageBean ImageBean);

    //图片删除
    @Update("<script>" +
            "update t_image_info" +
            "<set>" +
            " del_status = '1'" +
            "</set>" +
            "where id = #{i.id}" +
            "</script>")
    int delImage(@Param("i") ImageBean ImageBean);
}
